import 'package:fijkplayer/fijkplayer.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/service/smonkey_repository.dart';
import 'package:s_mankey/ui/widget/error_widget.dart';
import 'package:s_mankey/ui/widget/loading_widget.dart';
import 'package:video_player/video_player.dart';

class VideosDetail extends StatefulWidget {
  final arguments;

  VideosDetail({this.arguments});

  @override
  _VideosDetailState createState() => _VideosDetailState();
}

class _VideosDetailState extends State<VideosDetail> {
  final FijkPlayer player = FijkPlayer();
  var datas;

  _VideosDetailState();
  @override
  void initState() {
    super.initState();

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          elevation: AppCustomSize.AppBarElevation,
            title: Text('我的视频')),
        body:

    FutureBuilder(future: SmonkeysRepository.fetchVideosDetail(options: widget.arguments),builder:
    (BuildContext context, AsyncSnapshot snapshot) {

    /// 请求中
    if (snapshot.connectionState != ConnectionState.done) {
    return LoadingWidget();
    }
    /// 请求结束
    if (snapshot.hasError) {
    // 请求失败，显示错误
    return datasErrorWidget(errorTip: snapshot.error.toString(),);
    }
    datas = snapshot.data;
    player.setDataSource(datas['complex']['FD']['url'], autoPlay: true);
    // 请求成功，显示数据
    return (datas == null)? LoadingWidget():

    Container(
          alignment: Alignment.center,
          child: FijkView(
            player: player,
          ),
        );}),
    );
  }

  @override
  void dispose() {
    super.dispose();
    player.release();
  }
}
